// intarray.h
#ifndef INTARRAY_H
#define INTARRAY_H

class IntArray {
private:
    int* m_data;
    int m_size;
    int m_capacity;

    void resize(int newCapacity) {
        int* newData = new int[newCapacity];
        for (int i = 0; i < m_size; ++i) {
            newData[i] = m_data[i];
        }
        delete[] m_data;
        m_data = newData;
        m_capacity = newCapacity;
    }

public:
    IntArray() : m_data(nullptr), m_size(0), m_capacity(0) {}

    ~IntArray() {
        delete[] m_data;
    }

    void push_back(int value) {
        if (m_size >= m_capacity) {
            resize(m_capacity == 0 ? 4 : m_capacity * 2);
        }
        m_data[m_size++] = value;
    }

    void pop_front() {
        if (m_size <= 0) return;
        for (int i = 1; i < m_size; ++i) {
            m_data[i-1] = m_data[i];
        }
        m_size--;
    }

    int size() const { return m_size; }
    bool empty() const { return m_size == 0; }
    int& operator[](int index) { return m_data[index]; }
    const int& operator[](int index) const { return m_data[index]; }

    void clear() {
        delete[] m_data;
        m_data = nullptr;
        m_size = m_capacity = 0;
    }

    int front() const {
        return empty() ? 0 : m_data[0];
    }

    int back() const {
        return empty() ? 0 : m_data[m_size - 1];
    }

    void erase(int index) {
        if (index < 0 || index >= m_size) return;
        for (int i = index; i < m_size - 1; ++i) {
            m_data[i] = m_data[i + 1];
        }
        m_size--;
    }
};

#endif // INTARRAY_H
